﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.view.*;
    import com.tudou.home.view.ad.*;
    import com.tudou.track.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdCommand extends SimpleCommand
    {

        public function AdCommand()
        {
            return;
        }// end function

        private function sendTrack(param1:String, param2:Array = null) : void
        {
            var _loc_3:* = facade.retrieveProxy(AdProxy.NAME) as AdProxy;
            var _loc_4:* = facade.retrieveMediator(AdCptFloatMediator.NAME) as AdCptFloatMediator;
            if (_loc_3.adTracker && _loc_4.adItemInfo)
            {
                _loc_3.adTracker.adSend(_loc_4.adItemInfo, _loc_4.adThrowInfo, param1, param2);
            }
            return;
        }// end function

        private function allowBackAd() : Boolean
        {
            var _loc_1:* = PageInfo.getInstance().isListPlayer;
            return !_loc_1;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_11:IAdItemInfo = null;
            var _loc_12:Object = null;
            var _loc_13:PageInfo = null;
            var _loc_14:PageProxy = null;
            var _loc_2:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            var _loc_3:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            var _loc_4:* = facade.retrieveProxy(AdLoadingProxy.NAME) as AdLoadingProxy;
            var _loc_5:* = facade.retrieveProxy(AdListProxy.NAME) as AdListProxy;
            var _loc_6:* = facade.retrieveProxy(AdCornerProxy.NAME) as AdCornerProxy;
            var _loc_7:* = facade.retrieveMediator(SkinMediator.NAME) as SkinMediator;
            var _loc_8:* = facade.retrieveMediator(AdLoadingMediator.NAME) as AdLoadingMediator;
            var _loc_9:* = facade.retrieveMediator(AdCptFloatMediator.NAME) as AdCptFloatMediator;
            var _loc_10:* = facade.retrieveMediator(AdCornerMediator.NAME) as AdCornerMediator;
            switch(param1.getName())
            {
                case AdCommandSet.CLEAR_ALL:
                {
                    sendNotification(AdBackgroundCommandSet.CLEAR);
                    sendNotification(AdPauseCommandSet.CLEAR);
                    sendNotification(AdPlacardCommandSet.CLEAR);
                    sendNotification(AdOverlayCommandSet.CLEAR);
                    sendNotification(AdFrontCommandSet.CLEAR);
                    sendNotification(AdFrontLastCommandSet.CLEAR);
                    sendNotification(AdBackCommandSet.CLEAR);
                    sendNotification(ExternalCommandSet.REMOVE_AD_FRONT);
                    sendNotification(ExternalCommandSet.REMOVE_AD_FRONT_LAST);
                    sendNotification(ExternalCommandSet.REMOVE_AD_BACK);
                    _loc_4.stopLoad();
                    _loc_6.stopLoad();
                    _loc_8.clearAd();
                    _loc_10.clearAd();
                    AdConsts.reset();
                    break;
                }
                case AdCommandSet.ADINFO_START_LOAD:
                {
                    _loc_3.delayTime = PlayerConsts.AD_TIMEOUT_TIME * 1000;
                    _loc_2.isFormerAdShowed = false;
                    _loc_2.initFormerAdShowed();
                    _loc_2.load(PageInfo.getInstance());
                    StatusInfo.getInst().ad = StatusInfo.AD_HAS_REQUESTED;
                    break;
                }
                case AdCommandSet.ADINFO_LOAD_ERROR:
                {
                    break;
                }
                case AdCommandSet.ADINFO_SECURITY_ERROR:
                {
                    break;
                }
                case AdCommandSet.AD_CPT_FLOAT_LOADED:
                {
                    _loc_12 = param1.getBody();
                    if (_loc_9.setAdObj(_loc_12))
                    {
                        _loc_7.addFloatAd(_loc_9.getAdDisplay());
                        _loc_9.showAd();
                    }
                    break;
                }
                case AdCommandSet.AD_CPT_FLOAT_CLOSE:
                {
                    break;
                }
                case AdCommandSet.AD_CPT_FLOAT_CLICK:
                {
                    sendTrack(NodeLog.AD_CLICK, [null]);
                    break;
                }
                case AdCommandSet.AD_CPT_FLOAT_SHOW:
                {
                    _loc_9.showAd();
                    break;
                }
                case AdCommandSet.AD_CPT_FLOAT_HIDE:
                {
                    _loc_9.hideAd();
                    break;
                }
                case AdCommandSet.ADINFO_LOAD_COMPLETE:
                {
                    _loc_13 = PageInfo.getInstance();
                    if (_loc_2.throwInfo != null)
                    {
                        _loc_13.areaCode = _loc_2.throwInfo.areaCode;
                    }
                    if (!_loc_13.rurlId && _loc_2.rurlId)
                    {
                        _loc_13.rurlId = _loc_2.rurlId;
                        _loc_14 = facade.retrieveProxy(PageProxy.NAME) as PageProxy;
                        _loc_14.setRurlId(_loc_13.rurlId);
                    }
                    if (_loc_3.playerStatus.hasStartPlay)
                    {
                        sendNotification(AdBackgroundCommandSet.START);
                        sendNotification(AdCornerCommandSet.START);
                    }
                    else
                    {
                        sendNotification(AdFrontMultiCommandSet.START);
                    }
                    _loc_5.updateList(_loc_2.adCacheList);
                    sendNotification(PageCommandSet.GET_LIVE_DATA, _loc_2.liveXml);
                    break;
                }
                case AdCommandSet.ADLIST_CACHED:
                {
                    if (_loc_3.fullCached)
                    {
                        _loc_5.startCache();
                    }
                    break;
                }
                case PlayerCommandSet.VIDEO_NEAR_FINISH:
                {
                    _loc_11 = _loc_2.getAdItemByType(AdType.BACK);
                    if (_loc_11 && allowBackAd())
                    {
                        sendNotification(ExternalCommandSet.ADD_AD_BACK);
                        sendNotification(AdBackCommandSet.START);
                    }
                    break;
                }
                case PlayerCommandSet.VIDEO_FINISH:
                {
                    _loc_11 = _loc_2.getAdItemByType(AdType.BACK);
                    if (_loc_11 && allowBackAd())
                    {
                        sendNotification(AdBackCommandSet.START_PREPAREED);
                    }
                    else if (!PageInfo.getInstance().isListPlayer)
                    {
                        sendNotification(PageCommandSet.LOAD_SHARE_RELATIVE_DATA);
                        sendNotification(PlayerCommandSet.SHOW_PLAY_COMPLETE);
                    }
                    break;
                }
                case ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE:
                {
                    break;
                }
                case ViewCommandSet.NORMALSCREEN_RESIZE:
                {
                    break;
                }
                case PlayerCommandSet.FULL_CACHED:
                {
                    if (!_loc_5.caching)
                    {
                        _loc_5.startCache();
                    }
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
